import com.alibaba.fastjson.JSONObject;
import com.jiangruan.javainspect.Constants;
import com.jiangruan.javainspect.address.Address;
import com.jiangruan.javainspect.bean.HotVideo;
import com.jiangruan.javainspect.bean.HotVideoCommon;
import com.jiangruan.javainspect.bean.Idioncommon;
import com.jiangruan.javainspect.request.HttpUtils;
import com.jiangruan.javainspect.service.GetBestBlockHash;
import com.jiangruan.javainspect.service.GetIdiom;
import com.jiangruan.javainspect.service.HotVideoService;

import javax.swing.text.html.BlockView;
import java.security.KeyPair;
import java.util.List;
import java.util.Scanner;

/**
 * @author:liyaqi
 * @email:3441520483@qq.com
 * @desc:
 * @datatime:2021/12/7 21:57
 */
public class main {
    public static void main(String[] args) {
//        System.out.println("hello world");
//        HotVideoService service = new HotVideoService();
//        List<HotVideo> list = service.getHotVideo();
//        System.out.println(list.size());
        run();
    }

    public static void run() {
        System.out.println("====== 比特币系统设计期末考查系统 =====");
        System.out.println("本系统已实现以下功能");
        System.out.println("1.热门视频抓取  2.比特币客户端通信  3.比特币地址推导 4.成语接龙  0.退出");
        while (true) {
            userMenu();
        }

    }

    public static void userMenu() {
        System.out.println("请输入要使用的功能序号：");
        Scanner scanner = new Scanner((System.in));
        int num = scanner.nextInt();
        switch (num) {
            case 1://热门视频抓取
                HotVideoService service = new HotVideoService();
                HotVideoCommon hotVideo = service.getHotVideo();
                for (HotVideo video : hotVideo.getResult()) {
                    System.out.println(video.getShare_url());
                }
                break;
            case 2://比特币通信
                GetBestBlockHash getBestBlockHash = new GetBestBlockHash();
//                String blockhash=getBestBlockHash.getbestblockhash();
                System.out.println(getBestBlockHash.getbestblockhash().getResult());
//                System.out.println(blockhash);
                break;
            case 3://比特币地址导推
                Address address = new Address();
                KeyPair keyPair = address.generateKeys();
                String addr = address.newAddress(keyPair);
                boolean b = address.verifyAddress(addr);
                System.out.println(b);
                break;
            case 4://成语接龙
                GetIdiom getIdiom = new GetIdiom();
                Scanner scanner1 = new Scanner(System.in);
                String idiom = scanner1.next();
                Idioncommon getidiom = getIdiom.getidiom(idiom);
                break;
            case 0:
                System.out.println("谢谢使用，下次再见！");
                System.exit(0);
                break;

            default:
                System.out.println("输入有误，请重新输入");
                break;
        }

//
//        String url = Constants.TRIP_URL
//                + "?key=" + Constants.TRIP_key
//                + "&type=travel_overall"
//                + "&size=20";
//        String result = HttpUtils.get(url);
//        System.out.println(result);
//
//        //json解析
//        HotVideoCommon videoCommon = JSONObject.parseObject(result, HotVideoCommon.class);
//        System.out.println(videoCommon.getResult());
//        System.out.println(videoCommon.getError_code());
//        System.out.println(videoCommon.getResult().size());
    }
}

